import BaseScene from "./core/BaseScene";
import EventManager from "./core/EventManager";
import SceneNavigator from "./core/SceneNavigator";
import { WebSock } from "./net/WebSock";

const {ccclass, property} = cc._decorator;

@ccclass
export default class chat extends BaseScene {
    @property(cc.EditBox) edx_msg: cc.EditBox = null

    onLoad(){
        super.onLoad();
        EventManager.on('onConnected',this.onConnected)
        EventManager.on('onMessage',this.onMessage)
    }

    onDestroy(){
        EventManager.off('onConnected',this.onConnected)
        EventManager.off('onMessage',this.onMessage)
    }

    start(){
        WebSock.ins().connect({url:'ws://127.0.0.1:8000'})
    }

    onConnected(){
        console.log('链接成功')
        WebSock.ins().send('type=add&ming='+'UserName')
    }

    onMessage(msg){
        console.log(msg)
    }

    onSendClick(){

    }

    onClearClick(){

    }

    onBack(){
        SceneNavigator.back({});
    }
}
